﻿using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;

namespace FulcrumApi.helpers
{
	public class ParseObject
	{
		public static T fromXml<T>(Stream xmlContent)
			where T : class
		{
			XmlSerializer xs = new XmlSerializer(typeof(T));
			return xs.Deserialize(xmlContent) as T;
		}
		
		public static String toXml<T>(T obj) {
			XmlSerializer xs = new XmlSerializer(typeof(T));
			StringBuilder sb = new StringBuilder();
			MemoryStream stream = new MemoryStream();
			TextWriter writer = new StreamWriter(stream);
			xs.Serialize(writer, obj);
			writer.Close();
			
			return Encoding.UTF8.GetString(stream.GetBuffer());
		}
	}
}
